package com.seventh.associationsystem.service;

import com.seventh.associationsystem.bean.Announcement;
import com.seventh.associationsystem.bean.Association;
import com.seventh.associationsystem.repository.AnnouncementRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnnouncementService {

    @Autowired
    private AnnouncementRepository announcementRepository;

    public Page<Announcement> getAnnouncementsPageable(Association association, Pageable pageable) {
        return announcementRepository.findByAssociation(association, pageable);
    }

    public List<Announcement> getAnnouncements(Association association) {
        return announcementRepository.findByAssociation(association);
    }

    public Announcement getAnnouncement(String uid) {
        return announcementRepository.findByUid(uid);
    }

    public void addAnnouncement(Announcement announcement) {
        announcementRepository.save(announcement);
    }

    public void updateAnnouncement(Announcement announcement) {
        announcementRepository.save(announcement);
    }
}
